package com.jule.miaozhuapc.service.impl;

import javax.transaction.Transactional;

import com.jule.miaozhuapc.dao.CheckTodayDao;
import com.jule.miaozhuapc.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jule.miaozhuapc.dao.UserDao;
import com.jule.miaozhuapc.domain.WawaUser;
import com.jule.miaozhuapc.req.dto.WxUserInfo;
import com.jule.miaozhuapc.service.UserService;


@Service
@Transactional
public  class UserServiceImpl implements UserService {

	
	@Autowired
	UserDao dao;
	@Autowired
	CheckTodayDao checkTodayDao;

	@Override
	public WawaUser findByUsername(String username){
		return dao.findByUsername();
	}


	@Override
	public UserDto getUserDetail(Long userId) {

		if (userId == null) return null;

		WawaUser wawaUser = new WawaUser();
		wawaUser = dao.findByUserId(userId);
		// 取值
		UserDto userDto = new UserDto();
		userDto.setCoin(wawaUser.getCoin());
		userDto.setSucCount(wawaUser.getSucCount());
		userDto.setToken(wawaUser.getToken());
		userDto.setUserId(wawaUser.getId());
		userDto.setWxGender(wawaUser.getWxGender());
		userDto.setWxNickName(wawaUser.getWxNickName());
		userDto.setWxPic(wawaUser.getWxPic());
		// 判断今天是否已经登录
		//FIXME
		// userDto.setCheckToday(checkTodayDao.findByUserId(userId) != null);
		return userDto;
	}

	@Override
	public WawaUser findByToken(String token) {
		WawaUser user = dao.findByToken(token);
		return user;
	}
}
